@extends('layout.app')
@section('content')

    <div class="row">
        <div class="col-lg-12">
            <h3 class="page-header">提现审核</h3>
        </div>
        <!-- /.col-lg-12 -->
    </div>
    <!-- /.row -->
    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    数据统计
                </div>
                <div class="well">
                    <div class="row" >
                        <div class="col-xs-4 col-sm-4 col-md-4" style="display:flex;flex-direction: row;justify-content: flex-start;align-items: center;"><label style="line-height:20px;width:150px;">开始时间：</label><input style="background: #fff;" id="zstart" class="form-control" name="zstart" readonly/></div>
                        <div class="col-xs-4 col-sm-4 col-md-4" style="display:flex;flex-direction: row;justify-content: flex-start;align-items: center;"><label style="line-height:20px;width:150px;">结束时间：</label><input style="background: #fff;"  id="zend" class="form-control" name="zend" readonly/>&nbsp;</div>
                        <div class="col-xs-4 col-sm-4 col-md-4" style="display:flex;flex-direction: row;justify-content: flex-start;align-items: center;">
                            <label style="line-height:20px;width:60px;">状态：</label>
                            <select id="status" onchange="updateTable()" name="status" class="form-control">
                                <option value="unselect">请选择状态</option>
                                <option value="0">待审核</option>
                                <option value="2">审核通过</option>
                                <option value="9">审核不通过</option>
                                <option value="10">待打款</option>
                                <option value="30">打款成功</option>
                                <option value="31">自动打款成功</option>
                                <option value="41">自动打款失败</option>

                            </select>
                            <button id="search" class="btn btn-primary">搜索</button>
                        </div>
                    </div>
                </div>
                <!-- /.panel-heading -->
                <div class="panel-body">
                    <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
                        <thead>
                        <tr>
                            <th>序号</th>
                            <th>用户名</th>
                            {{--<th>头像</th>--}}
                            <th>提现金额</th>
                            <th>提现日期</th>
                            <th>状态</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>

                        </tbody>
                    </table>
                    <div id="pagination" style="float:right;" class="m-style">

                    </div>
                </div>
                <!-- /.panel-body -->
            </div>
            <!-- /.panel -->
        </div>
        <!-- /.col-lg-12 -->
    </div>
@section('jsscript')
    @parent
    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"></script>
    <script src="/vendor/bootstrap/js/bootstrap.min.js"></script>

    <!-- Metis Menu Plugin JavaScript -->
    <script src="/vendor/metisMenu/metisMenu.min.js"></script>
    <!-- DataTables JavaScript -->
    <script src="/vendor/datatables/js/jquery.dataTables.min.js"></script>
    <script src="/vendor/datatables-plugins/dataTables.bootstrap.min.js"></script>
    <script src="/vendor/datatables-responsive/dataTables.responsive.js"></script>
    <script src="/dist/js/sb-admin-2.js"></script>
    <script src="/vendor/pagination/jquery.pagination.js"></script>
    <script src="/vendor/datepick/bootstrap-datepicker.min.js"></script>
    <script src="/vendor/datepick/bootstrap-datepicker.zh-CN.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/vendor/pagination/common/reset.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/vendor/pagination/common/highlight.min.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/vendor/pagination/common/common.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/vendor/pagination/pagination.css" media="screen">
    <link rel="stylesheet" type="text/css" href="/vendor/pagination/pagination.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="/vendor/datepick/bootstrap-datepicker.min.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="http://apps.bdimg.com/libs/layer/2.1/skin/layer.css" rel="stylesheet">
    <script src="http://apps.bdimg.com/libs/layer/2.1/layer.js"></script>

    <script>
        var table=null;
        $(function() {

            $.fn.datepicker.dates['cn'] = {   //切换为中文显示
                days: ["周日", "周一", "周二", "周三", "周四", "周五", "周六", "周日"],
                daysShort: ["日", "一", "二", "三", "四", "五", "六", "七"],
                daysMin: ["日", "一", "二", "三", "四", "五", "六", "七"],
                months: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                monthsShort: ["一月", "二月", "三月", "四月", "五月", "六月", "七月", "八月", "九月", "十月", "十一月", "十二月"],
                today: "今天",
                clear: "清除"
            };

            $('#zstart').datepicker({
                // format: 'yyyy-mm-dd',
                autoclose: true, //自动关闭
                beforeShowDay: $.noop,    //在显示日期之前调用的函数
                calendarWeeks: false,     //是否显示今年是第几周
                clearBtn: false,          //显示清除按钮
                daysOfWeekDisabled: [],   //星期几不可选
                endDate: Infinity,        //日历结束日期
                forceParse: true,         //是否强制转换不符合格式的字符串
                format: 'yyyy-mm-dd',     //日期格式
                keyboardNavigation: true, //是否显示箭头导航
                language: 'cn',           //语言
                minViewMode: 0,
                orientation: "auto",      //方向
                rtl: false,
                startDate: -Infinity,     //日历开始日期
                startView: 0,             //开始显示
                todayBtn: false,          //今天按钮
                todayHighlight: false,    //今天高亮
                weekStart: 0              //星期几是开始
            });
            $('#zend').datepicker({
                // format: 'yyyy-mm-dd',
                autoclose: true, //自动关闭
                beforeShowDay: $.noop,    //在显示日期之前调用的函数
                calendarWeeks: false,     //是否显示今年是第几周
                clearBtn: false,          //显示清除按钮
                daysOfWeekDisabled: [],   //星期几不可选
                endDate: Infinity,        //日历结束日期
                forceParse: true,         //是否强制转换不符合格式的字符串
                format: 'yyyy-mm-dd',     //日期格式
                keyboardNavigation: true, //是否显示箭头导航
                language: 'cn',           //语言
                minViewMode: 0,
                orientation: "auto",      //方向
                rtl: false,
                startDate: -Infinity,     //日历开始日期
                startView: 0,             //开始显示
                todayBtn: false,          //今天按钮
                todayHighlight: false,    //今天高亮
                weekStart: 0              //星期几是开始
            });





            updateTable();
            $('#search').on('click',function(){
                updateTable();
            })
        });
        function check(id){
            $.ajax({
                url:'/admin/cash/pay_withdraw',
                type:'post',
                data:{
                    'withdrawId':id,
                    'action':'check'
                },
                success:function(res){
                    console.log(res)
                    if(res.code==0){
                        layer.msg('打款成功')
                    }else{
                        layer.alert('打款失败'+res.code+res.msg+'; '+((typeof(res.data)=='undefined')?'':res.data));
                        //alert('打款失败'+res.code+res.msg+'; '+((typeof(res.data)=='undefined')?'':res.data));
                        updateTable();
                    }

                }
            })
        }

        function check_refuse(id){
            $.ajax({
                url:'/admin/cash/pay_withdraw',
                type:'post',
                data:{
                    'withdrawId':id,
                    'action':'refuse_check'
                },
                success:function(res){
                    if(res.code==0) layer.msg('update status success!')
                }
            })
        }

        function updateTable(page=1){
            $.ajax({
                url:'/admin/cash/get_withdraw_list',
                type:'get',
                data:{
                    'page':page,
                    'pagesize':15,
                    'zstart':$('#zstart').val(),
                    'zend':$('#zend').val(),
                    'status':$('#status').val()
                },
                success:function(res){
                    console.log(res)
                    if(res.data.length<=0){
                        res.data = [];
                    }
                    if(table != null) table.destroy();
                    table = $('#dataTables-example').DataTable({
                        //res.data:[{"id":1,"amount":"2.0000","created_at":"444","status":"5555","nickname":"\u7389","head_img":"666","status_code":40}]

                        data: res.data,
                        responsive: true,
                        paging:false,
                        searching:false,
                        retrieve: true,
                        columns: [
                            { data: 'id' },
                            { data: 'nickname'},
                            //{ data: 'head_img' },
                            { data: 'amount' },
                            { data: 'created_at' },
                            { data: 'status' },
                            { data: 'status_code'},

                        ],

                    });

                    $("#pagination").pagination( {
                        pageCount: res.pagecount,
                        jump: true,
                        coping: true,
                        homePage: '首页',
                        endPage: '末页',
                        prevContent: '上页',
                        nextContent: '下页',
                        callback: function (api) {
                            var current_page = api.getCurrent()
                            updateTable(current_page)
                        }
                    });
                }
            })
        }
    </script>
@endsection
@endsection

